﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JLL.China.Infrastructure.Repositories.Listings
{
    using LINQ = JLL.China.Infrastructure.Repositories.LINQ2SQL;
    using JLL.China.Infrastructure.Repositories.Listings;
    using JLL.China.Model;

    public static class ListingFactory
    {
        public static Model.Listings FromLINQObject(LINQ.Listing listing)
        {
            if (listing == null)
            {
                return null;
            }
            else
            {
                var model = new Model.Listings
                {
                    ID = Int32.Parse(listing.Listing_ID.ToString()),
                    PropertyFor = listing.PropertyFor,
                    ProjectNameFID = listing.ProjectNameFID,
                    PropertyClsssm  = listing.PropertyClsssm,
                    StreetNameFID = listing.StreetNameFID,
                    PropertyTypeFID = listing.PropertyTypeFID,
                    CountryFID = listing.CountryFID,
                    CityFID = listing.CityFID,
                    LocaltionFID = listing.LocaltionFID,
                    SubAreaFID = listing.SubAreaFID,
                    Tenure = listing.Tenure,
                    FloorLevel = listing.FloorLevel,
                    TotalFloor = listing.TotalFloor,
                    FloorArea_SM = listing.FloorArea_SM,
                    FloorArea_SF = listing.FloorArea_SF,
                    FloorArea_SY = listing.FloorArea_SY,
                    FloorAreaUnit = listing.FloorAreaUnit,
                    LandArea_SF = listing.LandArea_SF,
                    LandArea_SM = listing.LandArea_SM,
                    LandArea_SY = listing.LandArea_SY,
                    AskingPriceLocal = listing.AskingPriceLocal,
                    AskingPriceUSD = listing.AskingPriceUSD,
                    PriceInRMBPerSQMLocal = listing.PriceInRMBPerSQMLocal,
                    PriceInRMBPerSQMUSD = listing.PriceInRMBPerSQMUSD,
                    ListingType = listing.ListingType,   
                    ListingCat = listing.ListingCat,
                    StatusFID = listing.StatusFID,
                    NewLaunch = listing.NewLaunch,
                    Longitude = listing.Longitude,
                    Latitude = listing.Latitude,
                    Bedroom = listing.Bedroom,
                    Bathroom = listing.Bathroom,
                    MemberFID = listing.MemberFID,
                    CreateDate = listing.CreateDate,
                    ListingDate = listing.ListingDate,
                    ListingExpiry = listing.ListingExpiry,
                    PriceUnit = listing.PriceUnit,
                    EfficiencyRate = listing.EfficiencyRate,
                    Auction = listing.Auction,
                    HouseNumber = listing.HouseNumber
                };
                return model;
            }
        }

        public static LINQ.Listing ToLINQObject(Model.Listings listing)
        {
            var model = new LINQ.Listing{
              Listing_ID = listing.ID,
              PropertyFor = listing.PropertyFor,
              ProjectNameFID = listing.ProjectNameFID,
              PropertyClsssm = listing.PropertyClsssm,
              StreetNameFID = listing.StreetNameFID,
              PropertyTypeFID = listing.PropertyTypeFID,
              CountryFID = listing.CountryFID,
              CityFID = listing.CityFID,
              LocaltionFID = listing.LocaltionFID,
              SubAreaFID = listing.SubAreaFID,
              Tenure = listing.Tenure,
              FloorLevel = listing.FloorLevel,
              TotalFloor = listing.TotalFloor,
              FloorArea_SM = listing.FloorArea_SM,
              FloorArea_SF = listing.FloorArea_SF,
              FloorArea_SY = listing.FloorArea_SY,
              FloorAreaUnit = listing.FloorAreaUnit,
              LandArea_SF = listing.LandArea_SF,
              LandArea_SM = listing.LandArea_SM,
              LandArea_SY = listing.LandArea_SY,
              AskingPriceLocal = listing.AskingPriceLocal,
              AskingPriceUSD = listing.AskingPriceUSD,
              PriceInRMBPerSQMLocal = listing.PriceInRMBPerSQMLocal,
              PriceInRMBPerSQMUSD = listing.PriceInRMBPerSQMUSD,
              ListingType = listing.ListingType,
              ListingCat = listing.ListingCat,
              StatusFID = listing.StatusFID,
              NewLaunch = listing.NewLaunch,
              Longitude = listing.Longitude,
              Latitude = listing.Latitude,
              Bedroom = listing.Bedroom,
              Bathroom = listing.Bathroom,
              MemberFID = listing.MemberFID,
              CreateDate = listing.CreateDate,
              ListingDate = listing.ListingDate,
              ListingExpiry = listing.ListingExpiry,
              PriceUnit = listing.PriceUnit,
              EfficiencyRate = listing.EfficiencyRate,
              Auction = listing.Auction,
              HouseNumber = listing.HouseNumber
            };
            return model;
        }
    }
}
